package com.ruoyi.caigou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caigou.domain.BuySuppliesPrice;
import com.ruoyi.caigou.service.IBuySuppliesPriceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购供应商报价Controller
 *
 * @author lvql
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/gybjGoods")
public class BuySuppliesPriceController extends BaseController
{
    @Autowired
    private IBuySuppliesPriceService buySuppliesPriceService;

    /**
     * 查询采购供应商报价列表
     */
    @RequiresPermissions("caigou:gybjGoods:list")
    @GetMapping("/list")
    public TableDataInfo list(BuySuppliesPrice buySuppliesPrice)
    {
        startPage();
        List<BuySuppliesPrice> list = buySuppliesPriceService.selectBuySuppliesPriceList(buySuppliesPrice);
        return getDataTable(list);
    }

    /**
     * 导出采购供应商报价列表
     */
    @RequiresPermissions("caigou:gybjGoods:export")
    @Log(title = "采购供应商报价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuySuppliesPrice buySuppliesPrice)
    {
        List<BuySuppliesPrice> list = buySuppliesPriceService.selectBuySuppliesPriceList(buySuppliesPrice);
        ExcelUtil<BuySuppliesPrice> util = new ExcelUtil<BuySuppliesPrice>(BuySuppliesPrice.class);
        util.exportExcel(response, list, "采购供应商报价数据");
    }

    /**
     * 获取采购供应商报价详细信息
     */
    @RequiresPermissions("caigou:gybjGoods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buySuppliesPriceService.selectBuySuppliesPriceById(id));
    }

    /**
     * 获取采购供应商报价详细信息
     */
    @RequiresPermissions("caigou:gybjGoods:query")
    @PostMapping(value = "/getByBuySupCode")
    public AjaxResult getByBuySupCode(@RequestBody List<String> codeList)
    {
//        return success(buySuppliesPriceService.selectBuySuppliesPriceById(id));
        logger.info("BuySuppliesPriceController getByBuySupCode {}", codeList.toString());
        if (codeList.isEmpty()){
            return error("缺少参数");
        }
        return AjaxResult.success(buySuppliesPriceService.selectBuySuppliesPriceListByCodeList(codeList));
    }

    /**
     * 新增采购供应商报价
     */
    @RequiresPermissions("caigou:gybjGoods:add")
    @Log(title = "采购供应商报价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuySuppliesPrice buySuppliesPrice)
    {
        return toAjax(buySuppliesPriceService.insertBuySuppliesPrice(buySuppliesPrice));
    }

    /**
     * 修改采购供应商报价
     */
    @RequiresPermissions("caigou:gybjGoods:edit")
    @Log(title = "采购供应商报价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuySuppliesPrice buySuppliesPrice)
    {
        return toAjax(buySuppliesPriceService.updateBuySuppliesPrice(buySuppliesPrice));
    }

    /**
     * 删除采购供应商报价
     */
    @RequiresPermissions("caigou:gybjGoods:remove")
    @Log(title = "采购供应商报价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buySuppliesPriceService.deleteBuySuppliesPriceByIds(ids));
    }
}
